<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "{{%ns_professional}}".
 *
 * @property integer $professional_id
 * @property integer $department_id
 * @property string $title
 *
 * @property NsClasses[] $nsClasses
 * @property NsDepartment $department
 */
class Professional extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%ns_professional}}';
    }

    /**
     * @TODO  : 获取所有AR对象ID=>title数组
     * @param : 
     * @return: array(id => title)
     * @author: Ray
     * @date  : 2014-09-26
     */
    public static function getDataList($id)
    {
        $model = static::find()->where('department_id = '.$id)->all();
        foreach($model as $elem)
        {
            $result[$elem->getPrimaryKey()] = $elem->title;
        }
        if(!isset($result))
        {
            $result = array();
        }
        return $result;
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['department_id', 'title'], 'required'],
            [['department_id'], 'integer'],
            [['title'], 'string', 'max' => 50]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'professional_id' => Yii::t('Professional', 'Professional ID'),
            'department_id' => Yii::t('Professional', 'Department ID'),
            'title' => Yii::t('Professional', 'Title'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getClasses()
    {
        return $this->hasMany(Classes::className(), ['professional_id' => 'professional_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDepartment()
    {
        return $this->hasOne(Department::className(), ['department_id' => 'department_id']);
    }
}
